﻿using System;
using System.Drawing;
using System.Collections.Generic;
using System.Windows.Forms;

namespace QAQ
{
    class GameCtrl
    {
        private MouseCtrl mMouseCtrl = null;
        public JoyControl mJoyControl = null;

        private Dictionary<string, Point> mDictPoints; 

        public GameCtrl()
        {
            mMouseCtrl = new MouseCtrl();
            mJoyControl = new JoyControl();
            mDictPoints=new Dictionary<string, Point>();
            mDictPoints.Add("NxtPage", new Point(886, 167));
            mDictPoints.Add("PrePage", new Point(808, 166));
            mDictPoints.Add("PwForm", new Point(800, 380));
            mDictPoints.Add("", new Point());
            
        //    mDictPoints.Add("", new Point());
        //    mDictPoints.Add("", new Point());
        //    mDictPoints.Add("", new Point());
        //
        }

        public void EnterRoom(IntPtr ProcessHandle,int index)
        {
            mMouseCtrl.MoveRelatedToProcess(ProcessHandle, ImgProc.mRoomListStartX[0] + ImgProc.mRoomListOffX[0, index] + ImgProc.mRoomListWidth[0] ,
                ImgProc.mRoomListStartY[0] + ImgProc.mRoomListOffY[0, index] + ImgProc.mRoomListHeight[0] / 2);
            System.Threading.Thread.Sleep(50);

            mJoyControl.Key(JoyControl.KEY_MOUSELEFT);

        }

        private void MoveAndClick(IntPtr ProcessHandle, string what)
        {
            Point mDestPoint = mDictPoints[what];
            mMouseCtrl.MoveRelatedToProcess(ProcessHandle, mDestPoint.X, mDestPoint.Y);
            System.Threading.Thread.Sleep(33);
            mJoyControl.Key(JoyControl.KEY_MOUSELEFT);
            System.Threading.Thread.Sleep(33);
        }

        public void NtPage(IntPtr ProcessHandle)
        {
            MoveAndClick(ProcessHandle, "NxtPage");
            System.Threading.Thread.Sleep(400);
        }
        public void PrPage(IntPtr ProcessHandle)
        {
            MoveAndClick(ProcessHandle, "PrePage");            
            System.Threading.Thread.Sleep(400);
        }
        public void ReadyToGo(IntPtr ProcessHandle)
        {
            System.Threading.Thread.Sleep(33);
            mJoyControl.Key(JoyControl.KEY_F9);
        }
        public void ExitGame(IntPtr ProcessHandle)
        {
            mJoyControl.Key(JoyControl.KEY_ESC);
            System.Threading.Thread.Sleep(33);
        }
        public void PressEnter(IntPtr ProcessHandle)
        {
            mJoyControl.Key(JoyControl.KEY_ENTER);
            System.Threading.Thread.Sleep(33);
        }
        public void MouseGoAway(IntPtr ProcessHandle)
        {
            System.Threading.Thread.Sleep(33);
            mMouseCtrl.MoveRelatedToProcess(ProcessHandle, 688, 300);
        }
        public void FocusPWForm(IntPtr ProcessHandle)
        {
            MoveAndClick(ProcessHandle, "PwForm");            
        }
        
        public void CreateRoomFocusPWForm(IntPtr ProcessHandle)
        {
            Point PromptLoc = new Point(740, 425);
            mMouseCtrl.MoveRelatedToProcess(ProcessHandle, PromptLoc.X, PromptLoc.Y);
            System.Threading.Thread.Sleep(33);
            mJoyControl.Key(JoyControl.KEY_MOUSELEFT);
            System.Threading.Thread.Sleep(33);
        }
        public void ChangeCompeteType(IntPtr ProcessHandle)
        {
            Point PromptLoc = new Point(1000, 256);
            mMouseCtrl.MoveRelatedToProcess(ProcessHandle, PromptLoc.X, PromptLoc.Y);
            System.Threading.Thread.Sleep(33);
            mJoyControl.Key(JoyControl.KEY_MOUSELEFT);
            System.Threading.Thread.Sleep(33);
        }

        public void GoClickCreatRoom(IntPtr ProcessHandle)
        {
            Point PromptLoc = new Point(900, 566);
            mMouseCtrl.MoveRelatedToProcess(ProcessHandle, PromptLoc.X, PromptLoc.Y);
            System.Threading.Thread.Sleep(33);
            mJoyControl.Key(JoyControl.KEY_MOUSELEFT);
            System.Threading.Thread.Sleep(33);
        }

        public void LeaveRoom(IntPtr ProcessHandle)
        {
            Point PromptLoc = new Point(1310, 64);
            mMouseCtrl.MoveRelatedToProcess(ProcessHandle, PromptLoc.X, PromptLoc.Y);
            System.Threading.Thread.Sleep(33);
            mJoyControl.Key(JoyControl.KEY_MOUSELEFT);
            System.Threading.Thread.Sleep(33);
        }
        public void ConfigRoom(IntPtr ProcessHandle)
        {
            Point PromptLoc = new Point(716, 65);
            mMouseCtrl.MoveRelatedToProcess(ProcessHandle, PromptLoc.X, PromptLoc.Y);
            System.Threading.Thread.Sleep(33);
            mJoyControl.Key(JoyControl.KEY_MOUSELEFT);
            System.Threading.Thread.Sleep(33);
        }
        public void EnterPassword(IntPtr ProcessHandle,string password)
        {
            Clipboard.SetText(password);
            mJoyControl.Key(JoyControl.KEY_PASTE);
            System.Threading.Thread.Sleep(100);
            
            mJoyControl.Key(JoyControl.KEY_ENTER);
            System.Threading.Thread.Sleep(800);            
        }
    }
}
